// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import vuex from 'vuex'
import store from './store/index.js';
import Global from './tools/global'; // 引入global.js=
import ElementUI from 'element-ui';
import VueVideoPlayer from 'vue-video-player'; //video播放器


import axios from './tools/axios';
import checkAuth from './tools/checkAuth.js'
import common from './tools/common'
import uploader from 'vue-simple-uploader'

import './assets/css/iconfont.css'
import { emoji } from './emoji/emoji.js'

Vue.prototype.emoji = emoji
import VueCropper from 'vue-cropper'
Vue.use(VueCropper)

import ImageViewer from "./components/base/image-viewer.vue";
Vue.component('ImageViewer', ImageViewer)

require('video.js/dist/video-js.css');
require('vue-video-player/src/custom-theme.css');
require('element-ui/lib/theme-chalk/index.css');
import 'element-ui/lib/theme-chalk/base.css';
import '../public/reset.css'
import '../public/css/ipm.css'



//异步组件
require("./path");



Vue.use(uploader);
Vue.use(VueVideoPlayer);
// Icon.inject('chameleon')


Vue.prototype.$ajax = axios
Vue.prototype.$g = Global; // 全局变量




// Vue.prototype.uploader = uploader
Vue.config.productionTip = false;


// 提交以后禁用按钮一段时间，防止重复提交
Vue.directive('preventReClick', {
    inserted(el, binding) {
        el.addEventListener('click', () => {
            if (!el.disabled) {
                el.classList.add('is-disabled')
                el.disabled = true
                setTimeout(() => {
                    el.disabled = false
                    el.classList.remove('is-disabled')
                }, binding.value || 1000)
            }
        })
    }
});


/** 
 * 首页跳转应用模块的时候，不断的点击图标，如果用户没权限，会弹出从上到下排列的很多条相同的错误提示，很影响美观，所以此处对ElementUI的Message重写
 *  
 */
import { Message } from 'element-ui'
// 为了实现Class的私有属性
const showMessage = Symbol('showMessage')
// single默认值true
class DonMessage {
    success(options, single = true) {
        this[showMessage]('success', options, single)
    }
    warning(options, single = true) {
        this[showMessage]('warning', options, single)
    }
    info(options, single = true) {
        this[showMessage]('info', options, single)
    }
    error(options, single = true) {
        this[showMessage]('error', options, single)
    }

    [showMessage](type, options, single) {
        if (single) {
            // 判断是否已存在Message
            if (document.getElementsByClassName('el-message').length === 0) {
                Message[type](options)
            }
        } else {
            Message[type](options)
        }
    }
}


Vue.use(ElementUI);
Vue.prototype.$message = new DonMessage()

// if( process.env.NODE_ENV =='production' ){
//     Vue.prototype.BASE_URL = Vue.prototype.$g.PROD_BASE_URL;
// }else{
//     Vue.prototype.BASE_URL = Vue.prototype.$g.DEV_BASE_URL;
// }

Vue.prototype.BASE_URL = sessionStorage.getItem('host_addr')



new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')